package edu.hawaii.halealohacli.command;

import static org.junit.Assert.assertTrue;
import java.util.Collection;
import java.util.HashMap;
import java.util.Set;
import javax.xml.datatype.XMLGregorianCalendar;
import org.junit.Test;
import org.wattdepot.client.WattDepotClient;
import org.wattdepot.resource.source.jaxb.Source;
import org.wattdepot.util.tstamp.Tstamp;

/**
 * A JUnit test class for RankTowers.
 * 
 * @author Yong Hong Hsu
 * @author Branden Ogata
 */
public class TestRankTowers {
  /**
   * Tests RankTower.
   * 
   * @throws Exception if there's an error with the server.
   */
  @Test
  public void test() throws Exception {
    WattDepotClient client = new WattDepotClient("http://server.wattdepot.org:8190/wattdepot/");
    XMLGregorianCalendar start = Tstamp.makeTimestamp();
    XMLGregorianCalendar end = Tstamp.makeTimestamp();
    HashMap<String, Double> map1 = new HashMap<String, Double>();
    Source source = client.getSources().get(0);
    RankTowers rank = new RankTowers();

    // set day to the day WattDepot was restored
    start.setMonth(11);
    start.setDay(24);
    start.setTime(0, 0, 0);
    end.setMonth(11);
    end.setDay(25);
    end.setTime(0, 0, 0);
    
    // Add sources and keys to the map
    map1.put("Lehua-10-telco", 300.0);
    map1.put("Lehua-04-telco", 500.0);
    map1.put("Lehua-08-telco", 200.0);

    // Create a set of keys
    Object obj1 = 200.0;
    Object obj2 = 300.0;
    Object obj3 = 500.0;
    Set<String> name = map1.keySet();

    // Create a collection of values
    Collection<Double> values = map1.values();
    Object[] obj = rank.rankTow(name, values);
    
    // Test that the values are as expected
    assertTrue("Check three objects should be same:", 
        obj[0].equals(obj1) && obj[1].equals(obj2)
        && obj[2].equals(obj3));
    rank.printResults(client, source, start, end);

  }
}
